#include <cstdio>
#include "includeall.h"

using namespace Oribi;

bool compareSpritePos(const Sprite& a, const Sprite& b)
{
    SDL_Point basePos[2];
    basePos[0] = a.getBasePosition();
    basePos[1] = b.getBasePosition();

    return (basePos[0].y <= basePos[1].y);
}

void BlitQueue::blitAll(SDL_Surface *surf)
{
    if (!surf)
        return;

    #ifdef BLITQUEUE_SORT_LAST
    toBlit.sort(compareSpritePos);
    #endif

    for (auto it = toBlit.begin(); it != toBlit.end(); ++it)
    {
        (*it).blitWithOffset(surf, globalOffset);
    }
}

Sprite *BlitQueue::queueSprite(const Sprite& spr)
{
    toBlit.push_back(spr);
    return &toBlit.back();
}

void BlitQueue::clear()
{
    toBlit.clear();
}
